package com.eeepay.eeepay_v2.view;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.eeepay.eeepay_v2.R;

/**
 * Created by zw on 2016/4/12 0012.
 * 右上角带删除的图片
 */
public class DeleteImageView extends RelativeLayout implements View.OnClickListener {

    private Context mContext;
    private ImageView imageView;
    private ImageView iv_delete;
    private OnDeleteClickListener listener;


    public DeleteImageView(Context context) {
        super(context);
        this.mContext = context;
        init();
        setWidget();
    }

    private void init() {
        LayoutInflater.from(mContext).inflate(R.layout.layout_image_view, this, true);
        imageView = (ImageView) findViewById(R.id.iv_image);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        iv_delete = (ImageView) findViewById(R.id.iv_image_delete);
    }

    private void setWidget() {
        iv_delete.setOnClickListener(this);
    }

    public ImageView getImageView(){
        return imageView;
    }

    public void setImageViewBitmap(Bitmap bitmap){
        imageView.setImageBitmap(bitmap);
    }

    @Override
    public void onClick(View v) {
        if(listener != null){
            listener.onDelete((String)getTag());
        }
    }

    public void setOnDeleteClickListener(OnDeleteClickListener listener) {
        this.listener = listener;
    }

    /**
     * 删除监听
     */
    public interface OnDeleteClickListener{
        void onDelete(String tag);
    }
}
